package tc.alert.tckejisoc.init;

import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.stereotype.Component;
import tc.alert.tckejisoc.cache.CacheData;
import tc.alert.tckejisoc.domain.SocBanned;
import tc.alert.tckejisoc.domain.SocIp;
import tc.alert.tckejisoc.rule.LogRuleManager;
import tc.alert.tckejisoc.service.SocBannedService;
import tc.alert.tckejisoc.service.SocIpService;
import tc.alert.tckejisoc.utils.HttpUtils;

import javax.annotation.PostConstruct;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@Component
@Slf4j
public class IndexInitializer {

    @Value("${xml-file-path}")
    private String path;
    @Autowired
    private RestHighLevelClient client;
    @Autowired
    private SocBannedService socBannedService;
    @Autowired
    private SocIpService socIpService;
    @Autowired
    private CacheData cacheData;
    @Autowired
    private LogRuleManager logRuleManager;
    private final ElasticsearchOperations elasticsearchOperations;

    public IndexInitializer(ElasticsearchOperations elasticsearchOperations) {
        this.elasticsearchOperations = elasticsearchOperations;
    }

    @PostConstruct
    public void init() throws URISyntaxException {


//        List<SocBanned> list = socBannedService.selectList(new SocBanned());
//        for (SocBanned socBanned : list) {
//            //数据全部写入缓存中  封禁的key
//            cacheData.put(socBanned.getIp().toString(), socBanned.getIp());
//        }
//
//        List<SocIp> sip = socIpService.list();
//        cacheData.put("socip", sip);
//
//
//        String property = System.getProperty("os.name");
//        log.info("系统名称=========" + property);
//        if (property.contains("Windows")) {
//            Path paths = Paths.get(ResourceLoader.class.getClassLoader().getResource("rule/").toURI());
//            path = paths.toFile().getAbsolutePath();
//        }
//        log.info("加载解析文件" + path);
//        logRuleManager.start(path);


    }
}